package com.goudan.demo.util;

public class StringFillUtil {

    public static String CHARSET_NAME = "UTF-8";
    public static char FILL_LEFT = 'L';

    public StringFillUtil() {
    }

    public static byte[] StringToBytes(String str) {
        try {
            return str != null && str.length() > 0 ? str.getBytes(CHARSET_NAME) : new byte[0];
        } catch (Exception var2) {
            return null;
        }
    }

    public static String LeftFill(String s, char c, int n) {
        return FILL(s, c, n, FILL_LEFT);
    }

    public static String FILL(String s, char c, int n, char f) {
        int iByteLen = StringToBytes(s).length;
        if (iByteLen >= n) {
            return s;
        } else {
            byte[] fillChars = new byte[n - iByteLen];

            for (int i = 0; i < fillChars.length; ++i) {
                fillChars[i] = (byte) c;
            }

            return f == FILL_LEFT ? new String(fillChars) + s : s + new String(fillChars);
        }
    }
}
